package wlt.plan;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import wlt.plan.controller.TodoManager;
import wlt.plan.view.TodoApp;

import java.util.Objects;

public class Launcher extends Application {
    @Override
    public void start(Stage primaryStage) {
        // 设置窗口标题
        primaryStage.setTitle("日程管理");
        
        // 创建TodoManager实例
        TodoManager manager = new TodoManager();
        
        // 创建TodoApp实例并传递TodoManager
        TodoApp todoApp = new TodoApp(manager);
        Scene scene = todoApp.createScene();
        
        // 设置应用图标，确保路径正确
        primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/photo/icon.png"))));
        primaryStage.setScene(scene);
        primaryStage.show();
        
        // 添加应用关闭时的处理，确保数据被保存
        primaryStage.setOnCloseRequest(event -> {
            manager.saveTasks();
        });
    }
    
    public static void main(String[] args) {
        launch();
    }
}